/* 
 * File:   widget_panel.cpp
 * Author: jolo
 * 
 * Created on 5. Oktober 2011, 19:02
 */


#include "widget_panel.hpp"

#include <QtGui/QLayout>

#include "labelled_line_edit.hpp"
#include "labelled_text_edit.hpp"
#include "labelled_spin_box.hpp"

#include "main_window.hpp"
#include "field_label.hpp"

namespace widgets
{

    widget_panel::widget_panel(QWidget* p, const QString& title)
    : group_box(title, p), lblCol_(0), wCol_(1), row_(0)
    {
        setLayout(new QGridLayout(this));
    }

    widget_panel::~widget_panel()
    {
    }

    void widget_panel::add(labelled_line_edit* w) {
        add(w->label(), w);
    }
    
    void widget_panel::add(labelled_text_edit* w) {
        add(w->label(), w);
    }
    
    void widget_panel::add(labelled_spin_box* w) {
        add(w->label(), w);
    }
    
    void widget_panel::add(field_label* lbl, QLineEdit* w) {
        lbl->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(lbl, row_, lblCol_);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(w, row_, wCol_);
        row_++;
    }
    
    void widget_panel::add(field_label* lbl, QSpinBox* w) {
        lbl->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(lbl, row_, lblCol_);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(w, row_, wCol_);
        row_++;
    }
    
    void widget_panel::add(field_label* lbl, QTextEdit* w) {
        lbl->setAlignment(Qt::AlignRight | Qt::AlignTop);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(lbl, row_, lblCol_);
        (dynamic_cast<QGridLayout*>(layout()))->addWidget(w, row_, wCol_);
        row_++;
    }
}